<?php
include_once 'mod.php';
$mod = new mod;
if ($_SERVER['REQUEST_METHOD']=='POST'){
    $good_name = $_POST['good_name'];
    $class = $_POST['class'];
    $style = $_POST['style'];
    $create_time = date('Y-m-d H:i:s');
    $update_time = date('Y-m-d H:i:s');
    if (empty($good_name)){
        die('商品名不能为空<a href="index.php">返回首页</a>');
    }
    if (empty($class)){
        die('类型不能为空<a href="index.php">返回首页</a>');
    }
    if (empty($style)){
        die('状态不能为空<a href="index.php">返回首页</a>');
    }
    $mysql = $mod->link();
    $sql = "insert into goods (`good_name`,`class`,`style`,`create_time`,`update_time`) values ('$good_name',$class,$style,'$create_time','$update_time')";
    $result = $mod->IDU($mysql,$sql);
    if ($result['flag']){
        echo'添加成功<a href="index.php">返回首页</a>';
    }else{
        print_r($sql);
        echo '添加失败<a href="index.php">返回首页</a>'.$result['msg'];
    }
}


?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>添加</title>
</head>
<body>
<form action="" method="post">
    <p>商品名:<input type="text" name="good_name"></p>
    <p>图片:<input type="file" name="file"></p>
    <p>类型:<select name="class">
            <option value="">===请选择类型===</option>
            <option value="1">水果</option>
            <option value="2">服饰</option>
            <option value="3">手机</option>
            <option value="4">电脑</option>
        </select>
    </p>
    <p>状态:<input type="radio" name="style" value="1">销售
        <input type="radio" name="style" value="2">售罄
    </p>
    <input type="submit" value="添加">
</form>

</body>
</html>
